#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct stu
{
	int y;
	int result;
};
bool compare(struct stu student1, struct stu student2)
{
	return student1.y > student2.y;
}
int main()
{
	int m = 0;
	scanf("%d", &m);
	struct stu* student = new struct stu[m];
	for (int i = 0; i < m; i++)
		scanf("%d%d", &student[i].y, &student[i].result);
	sort(student, student + m, compare);
	int* count = new int[m];
	//统计每个学生y作为阈值时的正确个数
	int out_count = 0;//最佳次数
	int out = 0;//最佳阈值
	for (int i = 0; i < m; i++)
	{
		count[i] = 0;
		if (i == 0)
		{
			for (int j = 0; j < m; j++)//判断第一个数据
			{
				if (student[j].y == student[i].y && student[j].result == 1)
					count[i]++;
				else if (student[j].y < student[i].y && student[j].result == 0)
					count[i]++;
				//比它小的全是0，比它大的全是1
			}
		}
		else
		{
			if (student[i].result == 0)
				count[i] = count[i - 1] - 1;
			else if (student[i].result == 1)
				count[i] = count[i - 1] + 1;
		}
		if (student[i].y != student[i - 1].y && i != 0 && count[i - 1] > out_count)
		{
			out_count = count[i - 1];
			out = student[i - 1].y;
		}
		if (i == m - 1 && count[i] > out_count)
		{
			out_count = count[i];
			out = student[i].y;
		}
	}
	printf("%d\n", out);
	return 0;
}